project(Client)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)
find_package(nlohmann_json REQUIRED)

if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64")
  message(STATUS "Matches aarch64 lib")
  file(GLOB CameraLib "lib/arm64/*.so")
  file(GLOB DaHengTL "lib/arm64/*.cti")
elseif(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")
  message(STATUS "Matches x86_64 lib")
  file(GLOB CameraLib "lib/x86_64/*.so")
  file(GLOB DaHengTL "lib/x86_64/*.cti")
endif()
aux_source_directory(src SOURCE_FILE)
aux_source_directory(src/FileFormat FILEFORMAT_FILE)
aux_source_directory(src/CameraDriver/Base CAMERADRIVER_BASE_FILE)
aux_source_directory(src/CameraDriver/DaHeng CAMERADRIVER_DAHENG_FILE)
aux_source_directory(src/CameraDriver/Virtual CAMERADRIVER_VIRTUAL_FILE)
aux_source_directory(src/CameraDriver/MindVision CAMERADRIVER_MINDVISION_FILE)

include_directories(inc)
include_directories(../Thrift/Client)
include_directories(../Broadcast/inc)
link_libraries(${CameraLib} fmt pthread spdlog::spdlog ClientIPC ClientPub)

add_executable(
  ThriftClient
  run/Control_thrift.cpp
  ${SOURCE_FILE}
  ${CAMERADRIVER_BASE_FILE}
  ${CAMERADRIVER_DAHENG_FILE}
  ${FILEFORMAT_FILE}
  ${CAMERADRIVER_VIRTUAL_FILE}
  ${CAMERADRIVER_MINDVISION_FILE})

if(NOT (${DISABLE_TEST} MATCHES "On"))
  add_executable(
    ControlCollege_test
    run/ControlCollege_test.cpp ${SOURCE_FILE} ${CAMERADRIVER_BASE_FILE}
    ${CAMERADRIVER_DAHENG_FILE} ${FILEFORMAT_FILE} ${CAMERADRIVER_VIRTUAL_FILE})

  add_executable(RecordFile_test run/RecordFile_test.cpp ${SOURCE_FILE}
                                 ${FILEFORMAT_FILE})

  add_executable(DahengDriver_test run/DahengDriver_test.cpp
                                   ${CAMERADRIVER_DAHENG_FILE})
  add_executable(DataIndex_test run/DataIndex_test.cpp ${FILEFORMAT_FILE})

  add_executable(MindVision_test run/MindVision_test.cpp
                                 ${CAMERADRIVER_MINDVISION_FILE})

endif()

install(TARGETS ThriftClient DESTINATION bin)
install(FILES ${CameraLib} DESTINATION lib)
install(FILES ${DaHengTL} DESTINATION lib)
